package top.hcode.hoj.service.admin;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import top.hcode.hoj.dao.group.GroupEntityService;
import top.hcode.hoj.exception.ServiceException;
import top.hcode.hoj.pojo.dto.QueryGroupDTO;
import top.hcode.hoj.pojo.entity.group.Group;
import top.hcode.hoj.pojo.vo.GroupVO;

/**
 * @author orangej
 * @since 2024/12/30
 */
@Slf4j
@Component
@RequiredArgsConstructor
public class AdminGroupService {
    private final GroupEntityService groupDao;

    public IPage<GroupVO> getGroupList(QueryGroupDTO queryGroupDto) {
        return null;
    }

    public void deleteGroup(Long id) {
        // check group member count
        if (groupDao.countMembers(id) > 0) {
            throw new ServiceException("团队成员不为空，无法删除");
        }
        
        // check team count
        if (groupDao.countTeams(id) > 0) {
            throw new ServiceException("团队下有团队，无法删除");
        }

        groupDao.removeById(id);
    }

    public void addGroup(Group group) {
        groupDao.save(group);
    }

    public void updateGroup(Group group) {
        groupDao.updateById(group);
    }

    public Group saveGroup(Group group) {
        return null;
    }

    public Group getGroupDetail(Long id) {
        return null;
    }
}
